package cc.Controller;

import cc.Entity.Category;
import cc.Entity.Results;
import cc.ServiceImpl.CategoryServiceImpl;
import cc.Utils.ListToResultUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: ${张智杰}
 * @Date: 2018/10/13 14:57
 * @Description:
 */
@Controller
public class CategoryController {
    @Autowired
    CategoryServiceImpl categoryServiceImpl;

    //添加类别
    @ResponseBody
    @RequestMapping(value = "/addCate",method = RequestMethod.POST)
    public Results  addCategory(@RequestBody Category category){
        if(categoryServiceImpl.addCategory(category) !=0 ){
            return  ListToResultUtil.getResult(true,"00","成功",null);

        }else{
            return ListToResultUtil.getResult(false,null,"失败",null);
        }
    }
    //查询所有类别
    @ResponseBody
    @RequestMapping(value = "/getcategory/{categoryId}",method = RequestMethod.GET)
    public Results getAllCategory(@PathVariable("categoryId")String categoryId){

        PageInfo pageInfo = new PageInfo(categoryServiceImpl.getAllCategory());
        List list1 = new ArrayList();
        list1.add(pageInfo);
        return  ListToResultUtil.getResult(true,"00","成功",list1);
    }
}
